package com.spdb.spdbfl.restful.project;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.spdb.spdbfl.config.BaseConfig;
import com.spdb.spdbfl.config.PathDefined;
import com.spdb.spdbfl.utils.*;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;


@Test(description = "项目新增、审批")
public class ProjectIT {

    public static final String operationCenterUrl = "/operationCenter/operationCenter";
    public static final String savePrjApprUrl = "/process/project/savePrjAppr";
    public static final String saveProjectApprovalInfoUrl = "/process/proApproval/saveProjectApprovalInfo";
    public static final String rptStsToBrainUrl = "/process/proApproval/rptStsToBrain";
    public static final String uploadUrl = "/zuul/document/attachment/upload?token=";
    public static final String saveFileUrl = "/document/attachment/saveFile";
    public static final String savePlanUrl  = "/process/plan/savePlan";
    public static final String startUrl = "/process/proApproval/start";
    static String domainUrl = BaseConfig.domainUrl;
    static String token = "";
    static String url = "";//新增/更新项目url
    static String url1 = "";//savePrjAppr
    static String url2 = "";//saveProjectApprovalInfo
    static String url3 = "";
    static String url4 = "";//上传文件Url
    static String url5 = "";//保存文件url
    static String url6 = ""; //保存项目方案url
    static String url7 = ""; //提交审批url
    static String projectId = "";
    static String projectName = "";
    static String leaseItemId = "";
    static String manager = "8af4e52656c4af8a0156c59ba4f30047";
    static String assistManager = "ff8080816bd64342016bd9b91f010000";
    static String director = "8af4e52656c4af8a0156c58df49c0022";
    static String custId = "9a6264a6a46d4de9a004ca7261b18d19";
    static String custName = "徐工集团工程机械股份有限公司";
    static String projectApprovalId = "";
    static String applicationId = "";//wf_application主键,wf_project_approval表外建
    static String staffId = "";//wf_application表STAFF_ID
    static String spvId = "00000000-5948-221b-0159-4841317a0002";
    static String spvName = "浦银金融租赁股份有限公司";

    @BeforeClass
    public void setUp() throws Exception {
        token = ConfigProperty.getProperty("liumToken");
    }

    @Test(description = "获取token，拼接url", priority = 0)
    public static void getTokenAndUrl(){
        token = ConfigProperty.getProperty("liumToken");
    }

    @Test(description = "新增/更新项目", priority = 1)
    public static void newProject() {
        url = domainUrl + operationCenterUrl;
        leaseItemId = ConfigProperty.getProperty("leaseItemId");
        System.out.println("配置中的leaseItemId:"+leaseItemId);
        String param = newProjectParam();
        HttpRequest httpRequest = new HttpRequest();
        String result = httpRequest.httpPost(url, token, param);

        JSONObject jsonResult = JSONObject.parseObject(result);
        JSONObject project = (JSONObject) jsonResult.get("project");
        projectId = project.get("tableid").toString();
        projectName = project.get("projectName").toString();
        System.out.println("projectId: " + projectId);
        System.out.println("projectName: " + projectName);
        ConfigProperty.updateProperty("projectId", projectId);
        ConfigProperty.updateProperty("projectName", projectName);
        Assert.assertEquals(jsonResult.get("code"), "200");
        Assert.assertEquals(jsonResult.get("msg").toString(), "succ");
    }

    @Test(description = "savePrjAppr", priority = 2)
    public static void savePrjAppr() {
        url1 = domainUrl + savePrjApprUrl;
        String param = savePrjApprParam();
        HttpRequest httpRequest = new HttpRequest();
        System.out.println("token:"+token);
        String result = httpRequest.httpPost(url1, token, param);

        JSONObject jsonResult = JSONObject.parseObject(result);
        Assert.assertEquals(jsonResult.get("code"), 0);
        Assert.assertEquals(jsonResult.get("error").toString(), "");
    }

    @Test(description = "saveProjectApprovalInfo", priority = 3)
    public static void saveProjectApprovalInfo() {
        url2 = domainUrl + saveProjectApprovalInfoUrl;
        String param = saveProjectApprovalInfoParam();
        HttpRequest httpRequest = new HttpRequest();
        String result = httpRequest.httpPost(url2, token, param);

        JSONObject jsonResult = JSONObject.parseObject(result);
        JSONObject data = (JSONObject) jsonResult.get("data");
        applicationId = (String) data.get("id");
        projectApprovalId = (String) data.get("projectApprovalId");
        staffId = (String) data.get("staffId");
        //更新配置
        ConfigProperty.updateProperty("applicationId", applicationId);
        ConfigProperty.updateProperty("projectApprovalId", projectApprovalId);
        ConfigProperty.updateProperty("staffId", staffId);
        Assert.assertEquals(jsonResult.get("code"), 0);
        Assert.assertEquals(jsonResult.get("msg").toString(), "");
    }

    @Test(description = "rptStsToBrain", priority = 4)
    public static void rptStsToBrain(String applyState, String node) {
        url3 = domainUrl + rptStsToBrainUrl;
        String param = rptStsToBrainParam(applyState, node);
        HttpRequest httpRequest = new HttpRequest();
        String result = httpRequest.httpPost(url3, token, param);

        JSONObject jsonResult = JSONObject.parseObject(result);
        Assert.assertEquals(jsonResult.get("code"), 0);
        Assert.assertEquals(jsonResult.get("msg").toString(), "");
    }

    @Test(description = "上传并保存文件")
    public static void upload(String attachmentType, String attachmentTypeName) {
        url4 = domainUrl + uploadUrl + token;
        System.out.println("上传文件Url:" + url4);
        applicationId = ConfigProperty.getProperty("applicationId");
        //13202-1(尽调报告)、13202-0(租赁物清单)
        MultiValueMap<String, Object> param = uploadParam(applicationId, attachmentType, attachmentTypeName);
        HttpRequest httpRequest = new HttpRequest();
        Object result = httpRequest.httpPostMultipart(url4, param);

        //获取返回信息
        System.out.println("上传文件接口返回:"+result);
        JSONObject jsonObject = JSONObject.parseObject(String.valueOf(result));
        JSONObject data = (JSONObject)jsonObject.get("data");
        String attachmentNo = (String)data.get("attachmentNo");
        System.out.println("attachmentNo:"+attachmentNo);

        url5 = domainUrl + saveFileUrl;
        System.out.println("保存文件url："+url5);
        //构建saveFile入参
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(data);
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("instId", "");
        jsonObject2.put("taskId", "");

        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("attachmentBaseJson", jsonArray.toJSONString());
        jsonObject1.put("doc", jsonObject2.toJSONString());
        String param1 = jsonObject1.toJSONString();
        System.out.println("保存文件入参:"+param1);

        String saveFileResult = httpRequest.httpPost(url5, token, param1);
        JSONObject jsonResult = JSONObject.parseObject(saveFileResult);
        Assert.assertEquals(jsonResult.get("code"), 0);
        Assert.assertEquals(jsonResult.get("error").toString(), "");
    }

    @Test(description = "保存项目方案")
    public static void savePlan(){
        url6 = domainUrl + savePlanUrl;
        String param = savePlanParam();
        HttpRequest httpRequest = new HttpRequest();
        String result = httpRequest.httpPost(url6, token, param);

        JSONObject jsonResult = JSONObject.parseObject(result);
        Assert.assertEquals(jsonResult.get("code"), 0);
        Assert.assertEquals(jsonResult.get("msg").toString(), "");
    }

    @Test(description = "提交审批")
    public static void start(){
        url7 = domainUrl + startUrl;
        String param = startParam();
        HttpRequest httpRequest = new HttpRequest();
        String result = httpRequest.httpPost(url7, token, param);

        JSONObject jsonResult = JSONObject.parseObject(result);
        Assert.assertEquals(jsonResult.get("code"), "200");
        Assert.assertEquals(jsonResult.get("msg").toString(), "success");
    }


    /**
     * 构建start入参
     * @return
     */
    private static String startParam() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("account", null);
        jsonObject.put("accountCheck", "0");
        jsonObject.put("allJudges", null);
        jsonObject.put("apiCaller", "01");
        jsonObject.put("appendSql", null);
        jsonObject.put("application", null);
        jsonObject.put("applyId", ConfigProperty.getProperty("applicationId"));
        jsonObject.put("applyState", null);
        jsonObject.put("approvalComment", null);
        jsonObject.put("approveOpinionSummaryExt", null);
        jsonObject.put("assistManager", assistManager);
        jsonObject.put("assistManagerRatio",  7);
        jsonObject.put("attachmentBase", null);
        jsonObject.put("attachmentBaseList", null);
        jsonObject.put("backDefinitionKey", null);
        jsonObject.put("bizDept", "10");
        jsonObject.put("bizDeptName", null);
        jsonObject.put("bizSource", "02");
        jsonObject.put("checkOpinion", null);
        jsonObject.put("content", null);
        jsonObject.put("creationBy", null);
        jsonObject.put("creationDate", null);
        jsonObject.put("currentNodeName", null);
        jsonObject.put("currentRole", null);
        jsonObject.put("currentUser", null);
        jsonObject.put("currnetPersionName", null);
        jsonObject.put("cust", null);
        jsonObject.put("custId", custId);
        jsonObject.put("custName",  custName);
        jsonObject.put("deptCodes", null);
        jsonObject.put("deptName", null);
        jsonObject.put("deputyInvolved", "0");
        jsonObject.put("director", director);
        jsonObject.put("docList", null);
        jsonObject.put("earinGrates", null);
        jsonObject.put("id", ConfigProperty.getProperty("applicationId"));
        jsonObject.put("instanceIdList", null);
        jsonObject.put("irr", null);
        jsonObject.put("isChairman", null);
        jsonObject.put("isDelete", null);
        jsonObject.put("isUrgent", null);
        jsonObject.put("judgesConveningTime", null);
        jsonObject.put("judgesNumber", null);
        jsonObject.put("leaseProjectExts", null);
        jsonObject.put("leaseTime", null);
        jsonObject.put("leaseType", "3-01-02");
        JSONArray jsonArray = new JSONArray();
        jsonArray.add("3-01-02");
        jsonObject.put("leaseTypeList", jsonArray);
        jsonObject.put("mainManagerRatio", 7);
        jsonObject.put("manager", manager);
        jsonObject.put("menuId", null);
        jsonObject.put("modificationBy", null);
        jsonObject.put("modificationDate", null);
        jsonObject.put("path", "yes");
        jsonObject.put("processDefinitionId", null);
        jsonObject.put("projectApprovalId", projectApprovalId);
        jsonObject.put("projectId", projectId);
        jsonObject.put("projectInfo", null);
        jsonObject.put("projectName", ConfigProperty.getProperty("projectName"));
        jsonObject.put("projectStatus", null);
        jsonObject.put("purchasePrincipal", null);
        jsonObject.put("recallFlag", "0");
        jsonObject.put("rejectId", null);
        jsonObject.put("requisitionResponseId", null);
        jsonObject.put("returnFlag", "0");
        jsonObject.put("riskRating", "AA");
        jsonObject.put("startStaffName", null);
        jsonObject.put("startTime", null);
        jsonObject.put("sts", null);
        jsonObject.put("targetId", null);
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("assignee", assistManager);
        jsonObject1.put("assigneeVarName", "workflow_project_approval_assist_manager");
        jsonObject1.put("taskDefId", "assist_manager_approval");
        JSONArray jsonArray1 = new JSONArray();
        jsonArray1.add(jsonObject1);
        jsonObject.put("taskAssigneeList", jsonArray1);
        jsonObject.put("titleName", null);
        return jsonObject.toJSONString();
    }


    /**
     * 构建saveFile入参
     * @return
     */
    private static String savePlanParam() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("amountUnit", null);
        jsonObject.put("approveAmount", null);
        jsonObject.put("approveTime", null);
        jsonObject.put("assistManager", assistManager);
        jsonObject.put("bizDept", "10");
        jsonObject.put("bizSource", "02");
        jsonObject.put("bizType", "4-10");
        jsonObject.put("branch", null);
        jsonObject.put("branchName", null);
        jsonObject.put("bu", null);
        jsonObject.put("businessType", "1-04");
        jsonObject.put("chanceOrProject", null);
        jsonObject.put("chargeRatio", "0.0");
        jsonObject.put("createTime", "2022-09-26 11:06:17.0");
        jsonObject.put("creator", null);
        jsonObject.put("credit", null);
        jsonObject.put("creditUse", null);
        jsonObject.put("crossMarket", null);
        jsonObject.put("currency", "CNY");
        jsonObject.put("custName", custName);
        jsonObject.put("depositAmount", "0.00");
        jsonObject.put("deptName", "");
        jsonObject.put("director", null);
        jsonObject.put("earinGrate", "5");
        jsonObject.put("finanAmount", null);
        jsonObject.put("financingAmount", "0.00");
        jsonObject.put("firstAmount", "0.00");
        jsonObject.put("firstFixedAmount", "500000000.00");
        jsonObject.put("firstFixedCollectType", "01");
        jsonObject.put("fiveClass", "A-1");
        JSONArray jsonArr = new JSONArray();
        jsonArr.add("A");
        jsonArr.add("1");
        jsonObject.put("fiveClassList", jsonArr);
        jsonObject.put("fourBigTwoStar", null);
        jsonObject.put("fromRemark", null);
        jsonObject.put("gracePerioNo", "0");
        jsonObject.put("guaranteeGrate", null);
        jsonObject.put("guaranteePeople", null);
        jsonObject.put("guaranteeThings", "");
        JSONArray jsonArr1 = new JSONArray();
        jsonArr1.add("A");
        jsonObject.put("guaranteeType", jsonArr1);
        jsonObject.put("idReference", null);
        jsonObject.put("industryPrice", "0.00");
        jsonObject.put("irr", "5");
        jsonObject.put("isAbs", null);
        jsonObject.put("isAssets", null);
        jsonObject.put("isBuyout", null);
        jsonObject.put("isDelete", null);
        jsonObject.put("isEffect", null);
        jsonObject.put("isInterDomain", null);
        jsonObject.put("isTransferLease", null);
        jsonObject.put("isUrgent", null);
        jsonObject.put("itemCategory", "");
        JSONArray jsonArr2 = new JSONArray();
        jsonObject.put("itemCategoryList", jsonArr2);
        jsonObject.put("itemName", ConfigProperty.getProperty("itemName"));
        jsonObject.put("leaseAmount", "1000000000.00");
        jsonObject.put("leaseModel", null);
        jsonObject.put("leasePrincipal", "1000000000.00");
        jsonObject.put("leaseQuality", "3-01");
        jsonObject.put("leaseTerm", "12");
        jsonObject.put("leaseType", "3-01-02");
        JSONArray jsonArr3 = new JSONArray();
        jsonArr3.add("3-01-02");
        jsonObject.put("leaseTypeList", jsonArr3);
        jsonObject.put("leasemodel", null);
        jsonObject.put("mainManager", manager);
        jsonObject.put("marketingStatus", null);
        jsonObject.put("meetingTime", null);
        jsonObject.put("othersThings", "5");
        jsonObject.put("passTime", null);
        jsonObject.put("payPerioNo", 2);
        jsonObject.put("paymentType", null);
        JSONArray jsonArr4 = new JSONArray();
        jsonObject.put("paymentTypeList", jsonArr4);
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("applicationId", ConfigProperty.getProperty("applicationId"));
        jsonObject1.put("planId", "");
        jsonObject1.put("processKey", "");
        jsonObject.put("plan", jsonObject1);
        jsonObject.put("preRentBeforeMonth", "0");
        jsonObject.put("proProjectId", null);
        jsonObject.put("proejctType", null);
        jsonObject.put("proejctType2", null);
        jsonObject.put("projectCode", GetBaseDataUtil.getProjectCode(ConfigProperty.getProperty("projectId")));
        jsonObject.put("projectDesc", null);
        jsonObject.put("projectId", ConfigProperty.getProperty("projectId"));
        jsonObject.put("projectName", ConfigProperty.getProperty("projectName"));
        jsonObject.put("purchasePrice", "0.00");
        jsonObject.put("purpose", "02");
        JSONArray jsonArr5 = new JSONArray();
        jsonArr5.add("02");
        jsonObject.put("purposeList", jsonArr5);
        jsonObject.put("rateBaseType", "3");
        jsonObject.put("rateBaseValue", 4.65);
        jsonObject.put("rateEnableDate", "2021-08-20");
        jsonObject.put("rateExecuteValues", "4.65000000");
        jsonObject.put("rateFloatType", "1-02");
        jsonObject.put("rateFloatValue", "0");
        jsonObject.put("rateType", "LPR5Y");
        jsonObject.put("recommendDate", null);
        jsonObject.put("recyclePeriod", "06");
        jsonObject.put("referee", null);
        jsonObject.put("remarks", null);
        jsonObject.put("rentCalcMode", "pmt-before");
        jsonObject.put("rentRate", null);
        jsonObject.put("rentRatio", null);
        jsonObject.put("replyAmount", null);
        jsonObject.put("replyTime", null);
        jsonObject.put("reportAmount", null);
        jsonObject.put("responsApprovalNo", null);
        jsonObject.put("riskRating", "AA");
        jsonObject.put("spvId", spvId);
        jsonObject.put("spvName", spvName);
        jsonObject.put("stsTime", null);
        jsonObject.put("taxType", null);
        jsonObject.put("totalPrice", "1000000000.00");
        jsonObject.put("updater", null);
        jsonObject.put("updaterTime", null);

        return jsonObject.toJSONString();
    }


    /**
     * 构建upload入参,13202-1(尽调报告)、13202-0(租赁物清单)
     * @return
     */
    public static MultiValueMap<String, Object> uploadParam(String applicationId, String attachmentType, String attachmentTypeName) {
        MultiValueMap<String, Object> mapReq = new LinkedMultiValueMap<>();
        mapReq.add("templateId", "");
        mapReq.add("attachmentType", attachmentType);
        mapReq.add("attachmentTypeName", attachmentTypeName);
        mapReq.add("businessNo", "");
        mapReq.add("businessType", "");
        mapReq.add("docNature", "1");
        mapReq.add("templateBelongId", "");
        mapReq.add("templateBelongName", "");
        mapReq.add("belongCompanyId", "");
        mapReq.add("belongCompanyName", "");
        mapReq.add("applicationId", applicationId);
        mapReq.add("subPath", "");
        mapReq.add("file", upload(getBinary()));
        return mapReq;
    }


    /**
     * 构建rptStsToBrain入参
     *
     * @return
     */
    private static String rptStsToBrainParam(String applyState, String node) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("applyState", "01");
        jsonObject.put("node", "draft");
        jsonObject.put("projectId", ConfigProperty.getProperty("projectId"));
        return jsonObject.toJSONString();
    }


    /**
     * 构建saveProjectApprovalInfo入参
     *
     * @return
     */
    private static String saveProjectApprovalInfoParam() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("applyState", 1);
        jsonObject.put("businessId", null);
        jsonObject.put("content", createContentParam());
        jsonObject.put("id", null);
        jsonObject.put("processDefinitionKey", "ProjectApproval");
        jsonObject.put("processDefinitionName", "项目审批");
        jsonObject.put("routerUrl", "workflow_project_approval");
        return jsonObject.toJSONString();
    }


    /**
     * 构建savePrjAppr入参
     *
     * @return
     */
    private static String savePrjApprParam() {
        projectId = ConfigProperty.getProperty("projectId");
        projectName = ConfigProperty.getProperty("projectName");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("accountCheck", "0");
        jsonObject.put("approveOpinionSummaryExt", null);
        jsonObject.put("assistManager", assistManager);
        jsonObject.put("assistManagerRatio", "5");
        jsonObject.put("attachmentBaseList", new JSONArray());
        jsonObject.put("bizDept", "10");
        jsonObject.put("bizSource", "02");
        jsonObject.put("checkOpinion", "");
        jsonObject.put("currentNodeName", null);
        jsonObject.put("custId", custId);
        jsonObject.put("custName", custName);
        jsonObject.put("deputyInvolved", "0");
        jsonObject.put("director", director);
        jsonObject.put("isChairman", "0");
        jsonObject.put("isUrgent", "0");
        jsonObject.put("judgesConveningTime", null);
        jsonObject.put("judgesNumber", null);
        jsonObject.put("leaseType", "3-01-02");
        JSONArray arr = new JSONArray();
        arr.add("3-01-02");
        jsonObject.put("leaseTypeList", arr);
        jsonObject.put("mainManagerRatio", "10");
        jsonObject.put("manager", manager);
        jsonObject.put("path", "yes");
        jsonObject.put("projectApprovalId", null);
        jsonObject.put("projectId", projectId);
        jsonObject.put("projectName", projectName);
        jsonObject.put("purchasePrincipal", null);
        jsonObject.put("recallFlag", "0");
        jsonObject.put("region", "01");
        jsonObject.put("returnFlag", "0");
        jsonObject.put("riskRating", "AA");
        jsonObject.put("showpurchasePrincipal", "");
        return jsonObject.toJSONString();
    }


    /**
     * 构建newProject入参
     *
     * @return
     */
    private static String newProjectParam() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("mainManager", manager);
        jsonObject.put("assistManager", assistManager);
        jsonObject.put("bizDept", "10");
        jsonObject.put("bizSource", "02");
        jsonObject.put("bizType", "4-10");
        jsonObject.put("branch", null);
        jsonObject.put("businessType", "1-04");
        jsonObject.put("currency", "CNY");
        jsonObject.put("custId", custId);
        jsonObject.put("custName", custName);
        jsonObject.put("deptName", "");
        jsonObject.put("fiveClass", "A-1");
        jsonObject.put("fromRemark", "这是项目简要说明");
        jsonObject.put("industryCategory", "C-02");
        jsonObject.put("leaseAmount", 1000000000);
        jsonObject.put("leaseItemId", leaseItemId);
        jsonObject.put("leaseModel", "01");
        jsonObject.put("leaseTerm", 12);
        jsonObject.put("leaseType", "3-01-02");
        jsonObject.put("loginId", manager);
        jsonObject.put("orgCode", "13479349-9");
        jsonObject.put("projectCode", "");
        jsonObject.put("projectName", CommonUtil.getRandomName("project"));
        jsonObject.put("tableid", "");

        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("className", "ProjectAddService");
        jsonObject1.put("method", "newProject");
        jsonObject1.put("param", jsonObject);
        return jsonObject1.toJSONString();
    }

    /**
     * 构建saveProjectApprovalInfo方法的content参数
     *
     * @return
     */
    public static String createContentParam() {
        JSONObject jsonObject = new JSONObject();
        projectId = ConfigProperty.getProperty("projectId");
        projectName = ConfigProperty.getProperty("projectName");
//        projectApprovalId = GetBaseDataUtil.getProjectApprovalId(projectId);
//        ConfigProperty.updateProperty("projectApprovalId", projectApprovalId);
//        jsonObject.put("projectApprovalId", ProjectIT.projectApprovalId);
        jsonObject.put("projectId", projectId);
        jsonObject.put("projectName", projectName);
        jsonObject.put("custId", custId);
        jsonObject.put("custName", custName);
        jsonObject.put("bizDept", "10");
        jsonObject.put("manager", manager);
        jsonObject.put("assistManager", assistManager);
        jsonObject.put("director", director);
        jsonObject.put("returnFlag", "0");
        jsonObject.put("isChairman", null);
        jsonObject.put("judgesNumber", null);
        jsonObject.put("judgesConveningTime", null);
        jsonObject.put("accountCheck", 0);
        jsonObject.put("creationBy", null);
        jsonObject.put("creationDate", null);
        jsonObject.put("isDelete", null);
        jsonObject.put("modificationBy", null);
        jsonObject.put("modificationDate", null);
        jsonObject.put("isUrgent", "0");
        jsonObject.put("bizDeptName", null);
        jsonObject.put("bizSource", "02");
        jsonObject.put("leaseType", "3-01-02");
        jsonObject.put("riskRating", "AA");
        JSONArray array = new JSONArray();
        array.add("3-01-02");
        jsonObject.put("leaseTypeList", array);
        jsonObject.put("mainManagerRatio", 10);
        jsonObject.put("assistManagerRatio", 5);
        jsonObject.put("deputyInvolved", 0);
        jsonObject.put("purchasePrincipal", null);
        jsonObject.put("leaseTime", null);
        jsonObject.put("earinGrates", null);
        jsonObject.put("deptCodes", null);
        jsonObject.put("menuId", null);
        jsonObject.put("currentRole", null);
        jsonObject.put("appendSql", null);
        jsonObject.put("account", null);
        jsonObject.put("currentUser", null);
        jsonObject.put("titleName", null);
        jsonObject.put("instanceIdList", null);
        jsonObject.put("startStaffName", null);
        jsonObject.put("startTime", null);
        jsonObject.put("currentNodeName", null);
        jsonObject.put("currnetPersionName", null);
//        jsonObject.put("applyId", "20220907164439373");
        jsonObject.put("deptName", null);
//        jsonObject.put("id", "20220907164439373");
        jsonObject.put("content", null);
        jsonObject.put("docList", null);
        jsonObject.put("sts", null);
        jsonObject.put("irr", null);
        jsonObject.put("checkOpinion", null);
        jsonObject.put("path", "yes");
        jsonObject.put("approvalComment", null);
        jsonObject.put("taskAssigneeList", null);
        jsonObject.put("targetId", null);
        jsonObject.put("rejectId", null);
        jsonObject.put("backDefinitionKey", null);
        jsonObject.put("projectStatus", null);
        jsonObject.put("apiCaller", "01");
        jsonObject.put("requisitionResponseId", null);
        jsonObject.put("allJudges", null);
        jsonObject.put("recallFlag", "0");
        jsonObject.put("processDefinitionId", null);
        jsonObject.put("projectInfo", null);
        jsonObject.put("leaseProjectExts", null);
        jsonObject.put("cust", null);
        jsonObject.put("application", null);
        jsonObject.put("approveOpinionSummaryExt", null);
        jsonObject.put("attachmentBase", null);
        jsonObject.put("attachmentBaseList", null);

        return jsonObject.toJSONString();
    }

    /**
     * 获取二进制文件
     *
     * @return
     */
    public static byte[] getBinary() {
        PathDefined pd = new PathDefined();
        String resourcesPath = pd.getResourcesPath();
        String filePath = resourcesPath + "/test.txt";
        byte[] bytes = null;
        try {
            File file = new File(filePath);
            MultipartFile multipartFile = FileUtil.getMultipartFile(file);
            String originalFilename = multipartFile.getOriginalFilename();
            bytes = multipartFile.getBytes();
            System.out.println("originalFilename:" + originalFilename);
            return bytes;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return bytes;
    }

    /**
     * 获取ByteArrayResource
     * @param fileData
     * @return
     */
    public static ByteArrayResource upload(byte[] fileData){
        //请求传参
        ByteArrayResource fileAsResource = new ByteArrayResource(fileData){
            @Override
            public String getFilename() {
                return "test.txt";
            }

            @Override
            public long contentLength() {
                return fileData.length;
            }
        };
        return fileAsResource;
    }

    /**
     * 获取二进制文件CommonsMultipartFile
     *
     * @return
     */
    public static MultipartFile getBinary1(){
        FileItem fileItem = createFileItem();
        MultipartFile cmFile = new CommonsMultipartFile(fileItem);
        return cmFile;
    }

    public static File getBinary2(){
        PathDefined pd = new PathDefined();
        String resourcesPath = pd.getResourcesPath();
        String filePath = resourcesPath + "/test.txt";
        File file = new File(filePath);
        return file;
    }

    public static FileItem  createFileItem() {
        PathDefined pd = new PathDefined();
        String resourcesPath = pd.getResourcesPath();
        String filePath = resourcesPath + "/test.txt";
        File file = new File(filePath);

        FileItemFactory factory = new DiskFileItemFactory(16, null);
        FileItem item = factory.createItem("test", "text/plain", true, file.getName());
        int bytesRead = 0;
        byte[] buffer = new byte[8192];
        FileInputStream fis = null;
        OutputStream os = null;
        try {
            fis = new FileInputStream(file);
            os = item.getOutputStream();
            while ((bytesRead = fis.read(buffer, 0, 8192)) != -1) {
                os.write(buffer, 0, bytesRead);//从buffer中得到数据进行写操作
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (os != null) {
                    os.close();
                }
                if (fis != null) {
                    fis.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return item;
    }


    public static void main(String[] args) {
        getBinary();
    }


}
